import requests


class TestIHRMLogin:
    # 登录成功
    def test_login_success(self):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        body = {"mobile": "13800000002", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=body)
        print("resp=", resp.json())

        # 断言
        assert 200 == resp.status_code
        assert True == resp.json().get('success')
        assert 10000 == resp.json().get('code')
        assert "操作成功！" == resp.json().get('message')

        # 用户名错误
    def test_password_error(self):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        body = {"mobile": "138000000028", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=body)
        print("resp=", resp.json())

        assert 200 == resp.status_code
        assert False == resp.json().get('success')
        assert 20001 == resp.json().get('code')
        assert "用户名或密码错误" == resp.json().get('message')

        # 密码错误
    def test_username_error(self):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        body = {"mobile": "13800000002", "password": "123457"}
        resp = requests.post(url=url, headers=header, json=body)
        print("resp=", resp.json())

        assert 200 == resp.status_code
        assert False == resp.json().get('success')
        assert 20001 == resp.json().get('code')
        assert "用户名或密码错误" == resp.json().get('message')
